package belf.migrate.engine.ddl.type.oracle;

import belf.migrate.api.model.QualifiersModel;
import belf.migrate.api.table.schema.Catalog;
import belf.migrate.engine.ddl.BaseDDLConvert;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Oracle2DMTypeConvert extends BaseDDLConvert {
    private final static String IDENTIFIER_QUOTES = "\""; //达梦数据库的标识符用双引号括起来

    public Oracle2DMTypeConvert(String objectName, String sql, Catalog sourceCatalog, Catalog sinkCatalog,
                                String schema, QualifiersModel qualifiersModel) {
        super(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
    }

    @Override
    public String convert() {
        // FIXME: 目前Oracle的自定义类型到达梦的转换，删除DM不支持的“EDITIONABLE”和“REF”），后续再完善
        Pattern pattern1 = Pattern.compile("\\sREF\\s", Pattern.CASE_INSENSITIVE);
        Matcher matcher1 = pattern1.matcher(sql);
        String result = matcher1.replaceAll(" ");
        Pattern pattern2 = Pattern.compile("\\sEDITIONABLE\\s", Pattern.CASE_INSENSITIVE);
        Matcher matcher2 = pattern2.matcher(result);
        result = matcher2.replaceAll(" ");
        return result;
    }

}
